import pandas as pd


def merge_excel_files(file1, file2, output_file):
    # 读取两个Excel文件
    df1 = pd.read_excel(file1, header=None)
    df2 = pd.read_excel(file2, header=None)

    # 取出file1的右边32列
    df1_right = df1.iloc[:, 32:64]

    # 取出file2的左边32列
    df2_left = df2.iloc[:, 0:32]

    # 创建一个新的DataFrame来存储合并后的内容
    merged_data = pd.DataFrame(index=range(64), columns=range(96), dtype=str)

    # 填充file1的前32列
    merged_data.iloc[:, 0:32] = df1.iloc[:, 0:32]

    # 合并右边的部分
    for i in range(64):
        for j in range(32):
            cell1 = df1_right.iloc[i, j]
            cell2 = df2_left.iloc[i, j]
            merged_data.iloc[i, j + 32] = f"{cell1}\n{cell2}"

    # 填充file2的后32列
    merged_data.iloc[:, 64:96] = df2.iloc[:, 32:64]

    # 保存合并后的文件
    merged_data.to_excel(output_file, index=False, header=False)
    print(f"Merged file saved to {output_file}")


# 示例用法
file1 = 'E:\\wafer52\\test\\flow_compare\\tile_(6_24,7_25).xlsx'
file2 = 'E:\\wafer52\\test\\flow_compare\\tile_(6_25,7_26).xlsx'
output_file = 'E:\\wafer52\\test\\flow_compare\\merged_file.xlsx'

merge_excel_files(file1, file2, output_file)
